package cn.iocoder.yudao.module.system.controller.admin.studentdashboard.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Schema(description = "管理后台 - 学生看板数据 Response VO")
@Data
public class StudentDashboardRespVO {

    @Schema(description = "学生基本信息")
    private StudentBasicInfo studentInfo;

    @Schema(description = "最新考试成绩信息")
    private LatestExamInfo latestExam;

    @Schema(description = "排名信息")
    private RankingInfo ranking;

    @Schema(description = "各科成绩排名")
    private Map<String, SubjectRankInfo> subjectRanking;

    @Schema(description = "成绩趋势分析")
    private ScoreTrendInfo scoreTrend;

    @Schema(description = "年级分数分布情况")
    private ScoreDistributionInfo scoreDistribution;

    @Schema(description = "考试对比数据（多次考试对比）")
    private List<ExamComparisonInfo> examComparisons;

    @Schema(description = "等效位次和等效分信息")
    private EquivalentScoreRankInfo equivalentScoreRank;
    
    @Schema(description = "最高分记录信息")
    private List<TopScoreRecordInfo> topScoreRecords;
    
    @Schema(description = "学生参与的所有考试列表")
    private List<StudentExamInfo> studentExams;

    @Schema(description = "我的目标分析")
    private List<GoalAnalysisInfo> goalAnalysis;

    /**
     * 学生基本信息
     */
    @Data
    public static class StudentBasicInfo {
        @Schema(description = "学生ID", example = "1001")
        private Long studentId;

        @Schema(description = "学生姓名", example = "张三")
        private String studentName;

        @Schema(description = "学号", example = "G3C1001")
        private String studentNo;

        @Schema(description = "班级ID", example = "1")
        private Long classId;

        @Schema(description = "班级名称", example = "高三(1)班")
        private String className;

        @Schema(description = "年级", example = "高三")
        private String grade;
    }

    /**
     * 最新考试信息
     */
    @Data
    public static class LatestExamInfo {
        @Schema(description = "考试ID", example = "1")
        private Long examId;

        @Schema(description = "考试名称", example = "2024年高三上学期期中考试")
        private String examName;

        @Schema(description = "考试类型", example = "期中考试")
        private String examType;

        @Schema(description = "考试时间", example = "2024-01-15 08:30:00")
        private LocalDateTime examDate;

        @Schema(description = "总分", example = "684.5")
        private BigDecimal totalScore;

        @Schema(description = "满分", example = "750.0")
        private BigDecimal fullScore;

        @Schema(description = "各科成绩")
        private Map<String, BigDecimal> subjectScores;
        
        @Schema(description = "选科组合", example = "物化生")
        private String subjectCombination;
        
        @Schema(description = "首选科目", example = "物理")
        private String firstSubject;
        
        @Schema(description = "再选科目", example = "化学,生物")
        private String secondSubject;
        
        @Schema(description = "省份", example = "安徽")
        private String province;
        
        @Schema(description = "总分赋分", example = "690.5")
        private BigDecimal totalScoreAssigned;
        
        @Schema(description = "总分联考排名", example = "8")
        private Integer totalUnionRank;
        
        @Schema(description = "各科赋分成绩")
        private Map<String, BigDecimal> subjectAssignedScores;
        
        @Schema(description = "组合排名", example = "5")
        private Integer combinationRank;
        
        @Schema(description = "校内排名", example = "12")
        private Integer schoolRank;
    }

    /**
     * 排名信息
     */
    @Data
    public static class RankingInfo {
        @Schema(description = "班级排名", example = "1")
        private Integer classRank;

        @Schema(description = "班级总人数", example = "45")
        private Integer classTotalCount;

        @Schema(description = "年级排名", example = "2")
        private Integer gradeRank;

        @Schema(description = "年级总人数", example = "200")
        private Integer gradeTotalCount;

        @Schema(description = "校内排名", example = "5")
        private Integer schoolRank;

        @Schema(description = "联考排名", example = "12")
        private Integer unionRank;

        @Schema(description = "组合排名", example = "3")
        private Integer combinationRank;

        @Schema(description = "选科组合", example = "物化生")
        private String subjectCombination;

        @Schema(description = "班级排名百分位", example = "97.8")
        private BigDecimal classPercentile;

        @Schema(description = "年级排名百分位", example = "99.0")
        private BigDecimal gradePercentile;
    }

    /**
     * 各科排名信息
     */
    @Data
    public static class SubjectRankInfo {
        @Schema(description = "科目名称", example = "数学")
        private String subjectName;

        @Schema(description = "成绩", example = "145.0")
        private BigDecimal score;

        @Schema(description = "满分", example = "150.0")
        private BigDecimal fullScore;

        @Schema(description = "原始分", example = "143.0")
        private BigDecimal originalScore;

        @Schema(description = "赋分（选考科目）", example = "145.0")
        private BigDecimal assignedScore;

        @Schema(description = "等级（选考科目）", example = "A+")
        private String gradeLevel;

        @Schema(description = "班级排名", example = "1")
        private Integer classRank;

        @Schema(description = "年级排名", example = "3")
        private Integer gradeRank;

        @Schema(description = "校内排名", example = "5")
        private Integer schoolRank;

        @Schema(description = "联考排名", example = "12")
        private Integer unionRank;

        @Schema(description = "班级平均分", example = "128.5")
        private BigDecimal classAvgScore;

        @Schema(description = "年级平均分", example = "125.2")
        private BigDecimal gradeAvgScore;

        @Schema(description = "超过班级百分比", example = "95.6")
        private BigDecimal classBeatPercentage;

        @Schema(description = "超过年级百分比", example = "92.5")
        private BigDecimal gradeBeatPercentage;

        @Schema(description = "是否为选考科目", example = "true")
        private Boolean isElectiveSubject;
    }

    /**
     * 成绩趋势信息
     */
    @Data
    public static class ScoreTrendInfo {
        @Schema(description = "趋势数据点")
        private List<TrendDataPoint> trendData;

        @Schema(description = "总分趋势")
        private TrendAnalysis totalScoreTrend;

        @Schema(description = "各科趋势")
        private Map<String, TrendAnalysis> subjectTrends;
    }

    /**
     * 趋势数据点
     */
    @Data
    public static class TrendDataPoint {
        @Schema(description = "考试ID", example = "1")
        private Long examId;

        @Schema(description = "考试名称", example = "期中考试")
        private String examName;

        @Schema(description = "考试时间", example = "2024-01-15")
        private LocalDateTime examDate;

        @Schema(description = "总分", example = "684.5")
        private BigDecimal totalScore;

        @Schema(description = "班级排名", example = "1")
        private Integer classRank;

        @Schema(description = "年级排名", example = "2")
        private Integer gradeRank;

        @Schema(description = "各科成绩")
        private Map<String, BigDecimal> subjectScores;
        
        @Schema(description = "总分赋分", example = "690.5")
        private BigDecimal totalScoreAssigned;
        
        @Schema(description = "总分联考排名", example = "8")
        private Integer totalUnionRank;
        
        @Schema(description = "组合排名", example = "5")
        private Integer combinationRank;
        
        @Schema(description = "校内排名", example = "12")
        private Integer schoolRank;
    }

    /**
     * 趋势分析
     */
    @Data
    public static class TrendAnalysis {
        @Schema(description = "趋势方向", example = "UP")
        private String trendDirection; // UP, DOWN, STABLE

        @Schema(description = "变化幅度", example = "15.5")
        private BigDecimal changeAmount;

        @Schema(description = "变化百分比", example = "2.3")
        private BigDecimal changePercentage;

        @Schema(description = "连续上升次数", example = "3")
        private Integer consecutiveUpCount;

        @Schema(description = "连续下降次数", example = "0")
        private Integer consecutiveDownCount;

        @Schema(description = "最高分", example = "690.0")
        private BigDecimal highestScore;

        @Schema(description = "最低分", example = "650.0")
        private BigDecimal lowestScore;

        @Schema(description = "平均分", example = "672.5")
        private BigDecimal averageScore;

        @Schema(description = "最大值", example = "690.0")
        private BigDecimal maxValue;

        @Schema(description = "最小值", example = "650.0")
        private BigDecimal minValue;

        @Schema(description = "平均值", example = "672.5")
        private BigDecimal averageValue;

        @Schema(description = "变化范围", example = "40.0")
        private BigDecimal changeRange;

        @Schema(description = "波动系数", example = "0.15")
        private BigDecimal volatilityCoefficient;
    }

    /**
     * 分数分布信息
     */
    @Data
    public static class ScoreDistributionInfo {
        @Schema(description = "学生在年级中的位置")
        private StudentPositionInfo studentPosition;

        @Schema(description = "分数段分布")
        private List<ScoreRangeInfo> scoreRanges;

        @Schema(description = "年级统计信息")
        private GradeStatistics gradeStats;
    }

    /**
     * 学生位置信息
     */
    @Data
    public static class StudentPositionInfo {
        @Schema(description = "学生分数", example = "684.5")
        private BigDecimal studentScore;

        @Schema(description = "超过的学生数", example = "198")
        private Integer studentsBelow;

        @Schema(description = "分数相同的学生数", example = "1")
        private Integer studentsEqual;

        @Schema(description = "分数更高的学生数", example = "1")
        private Integer studentsAbove;

        @Schema(description = "百分位排名", example = "99.0")
        private BigDecimal percentileRank;
    }

    /**
     * 分数段信息
     */
    @Data
    public static class ScoreRangeInfo {
        @Schema(description = "分数段", example = "680-700")
        private String scoreRange;

        @Schema(description = "人数", example = "15")
        private Integer count;

        @Schema(description = "占比", example = "7.5")
        private BigDecimal percentage;

        @Schema(description = "是否包含当前学生", example = "true")
        private Boolean includesStudent;
    }

    /**
     * 年级统计信息
     */
    @Data
    public static class GradeStatistics {
        @Schema(description = "年级总人数", example = "200")
        private Integer totalStudents;

        @Schema(description = "最高分", example = "720.0")
        private BigDecimal maxScore;

        @Schema(description = "最低分", example = "450.0")
        private BigDecimal minScore;

        @Schema(description = "平均分", example = "580.5")
        private BigDecimal avgScore;

        @Schema(description = "中位数", example = "575.0")
        private BigDecimal medianScore;

        @Schema(description = "标准差", example = "65.2")
        private BigDecimal standardDeviation;
    }

    /**
     * 考试对比信息
     */
    @Data
    public static class ExamComparisonInfo {
        @Schema(description = "考试ID", example = "1")
        private Long examId;

        @Schema(description = "考试名称", example = "期中考试")
        private String examName;

        @Schema(description = "考试时间", example = "2024-01-15")
        private LocalDateTime examDate;

        @Schema(description = "总分", example = "684.5")
        private BigDecimal totalScore;

        @Schema(description = "班级排名", example = "1")
        private Integer classRank;

        @Schema(description = "年级排名", example = "2")
        private Integer gradeRank;

        @Schema(description = "与上次考试的分数差", example = "15.5")
        private BigDecimal scoreDifference;

        @Schema(description = "与上次考试的排名变化", example = "2")
        private Integer rankChange;

        @Schema(description = "各科成绩对比")
        private Map<String, SubjectComparisonInfo> subjectComparisons;
        
        @Schema(description = "总分赋分", example = "690.5")
        private BigDecimal totalScoreAssigned;
        
        @Schema(description = "总分联考排名", example = "8")
        private Integer totalUnionRank;
        
        @Schema(description = "组合排名", example = "5")
        private Integer combinationRank;
        
        @Schema(description = "校内排名", example = "12")
        private Integer schoolRank;
        
        @Schema(description = "选科组合", example = "物化生")
        private String subjectCombination;
    }

    /**
     * 科目对比信息
     */
    @Data
    public static class SubjectComparisonInfo {
        @Schema(description = "科目名称", example = "数学")
        private String subjectName;

        @Schema(description = "当前成绩", example = "145.0")
        private BigDecimal currentScore;

        @Schema(description = "上次成绩", example = "138.0")
        private BigDecimal previousScore;

        @Schema(description = "分数变化", example = "7.0")
        private BigDecimal scoreDifference;

        @Schema(description = "当前排名", example = "1")
        private Integer currentRank;

        @Schema(description = "上次排名", example = "3")
        private Integer previousRank;

        @Schema(description = "排名变化", example = "2")
        private Integer rankChange;
    }

    /**
     * 等效位次和等效分信息
     */
    @Data
    public static class EquivalentScoreRankInfo {
        @Schema(description = "学生原始成绩", example = "684.5")
        private BigDecimal originalScore;

        @Schema(description = "特控线分数", example = "680.0")
        private BigDecimal controlLineScore;

        @Schema(description = "特控线名称", example = "985院校参考线")
        private String controlLineName;

        @Schema(description = "省份", example = "山东")
        private String province;

        @Schema(description = "考试类型", example = "物理类")
        private String examType;

        @Schema(description = "成绩与特控线差值", example = "4.5")
        private BigDecimal scoreDifference;

        @Schema(description = "2023年等效分", example = "513.5")
        private BigDecimal equivalentScore2023;

        @Schema(description = "2024年等效分", example = "518.5")
        private BigDecimal equivalentScore2024;

        @Schema(description = "2025年等效分", example = "523.5")
        private BigDecimal equivalentScore2025;

        @Schema(description = "2023年等效位次", example = "15200")
        private Integer equivalentRank2023;

        @Schema(description = "2024年等效位次", example = "14800")
        private Integer equivalentRank2024;

        @Schema(description = "2025年等效位次", example = "14500")
        private Integer equivalentRank2025;

        @Schema(description = "2023年高考省控线", example = "509.0")
        private BigDecimal provinceControlLine2023;

        @Schema(description = "2024年高考省控线", example = "514.0")
        private BigDecimal provinceControlLine2024;

        @Schema(description = "2025年高考省控线", example = "519.0")
        private BigDecimal provinceControlLine2025;

        @Schema(description = "计算时间")
        private LocalDateTime calculationDate;

        @Schema(description = "计算状态", example = "1")
        private Integer calculationStatus;

        @Schema(description = "错误信息")
        private String errorMessage;

        @Schema(description = "三年等效位次趋势分析")
        private EquivalentRankTrendInfo rankTrend;

    }

    /**
     * 等效位次趋势分析
     */
    @Data
    public static class EquivalentRankTrendInfo {
        @Schema(description = "位次变化趋势", example = "IMPROVING")
        private String trendDirection; // IMPROVING, DECLINING, STABLE

        @Schema(description = "三年平均位次", example = "14833")
        private Integer averageRank;

        @Schema(description = "最好位次", example = "14500")
        private Integer bestRank;

        @Schema(description = "最差位次", example = "15200")
        private Integer worstRank;

        @Schema(description = "位次改善幅度", example = "700")
        private Integer improvementRange;

        @Schema(description = "位次稳定性评分", example = "85.5")
        private BigDecimal stabilityScore;

        @Schema(description = "趋势分析说明", example = "等效位次呈现稳步上升趋势，表现优秀")
        private String trendDescription;
    }
    
    /**
     * 最高分记录信息
     */
    @Data
    public static class TopScoreRecordInfo {
        @Schema(description = "记录ID", example = "1")
        private Long id;
        
        @Schema(description = "考试ID", example = "1")
        private Long examId;
        
        @Schema(description = "学生ID", example = "1001")
        private Long studentId;
        
        @Schema(description = "排名", example = "1")
        private Integer rank;
        
        @Schema(description = "科目名称", example = "数学")
        private String subjectName;
        
        @Schema(description = "原始分数", example = "145.0")
        private BigDecimal originalScore;
        
        @Schema(description = "赋分分数", example = "148.0")
        private BigDecimal assignedScore;
        
        @Schema(description = "联考排名", example = "1")
        private Integer unionRank;
        
        @Schema(description = "校内排名", example = "1")
        private Integer schoolRank;
        
        @Schema(description = "班级排名", example = "1")
        private Integer classRank;
        
        @Schema(description = "备注", example = "数学单科第一名")
        private String remark;
        
        @Schema(description = "创建时间")
        private LocalDateTime createTime;
    }
    
    /**
     * 学生参与的考试信息
     */
    @Data
    public static class StudentExamInfo {
        @Schema(description = "考试ID", example = "1")
        private Long examId;
        
        @Schema(description = "考试名称", example = "2024年高三上学期期中考试")
        private String examName;
        
        @Schema(description = "考试类型", example = "期中考试")
        private String examType;
        
        @Schema(description = "考试时间", example = "2024-01-15 08:30:00")
        private LocalDateTime examDate;
        
        @Schema(description = "考试状态", example = "已完成")
        private String examStatus;
        
        @Schema(description = "是否有成绩", example = "true")
        private Boolean hasScore;
        
        @Schema(description = "总分", example = "684.5")
        private BigDecimal totalScore;
        
        @Schema(description = "满分", example = "750.0")
        private BigDecimal fullScore;
        
        @Schema(description = "班级排名", example = "1")
        private Integer classRank;
        
        @Schema(description = "年级排名", example = "2")
        private Integer gradeRank;

        @Schema(description = "校内排名", example = "5")
        private Integer schoolRank;
        
        @Schema(description = "联考排名", example = "12")
        private Integer unionRank;
        
        @Schema(description = "组合排名", example = "3")
        private Integer combinationRank;
        
        @Schema(description = "选科组合", example = "物化生")
        private String subjectCombination;
        
        @Schema(description = "省份", example = "安徽")
        private String province;
        
        @Schema(description = "班级ID", example = "1")
        private Long classId;
        
        @Schema(description = "班级名称", example = "高三(1)班")
        private String className;
        
        @Schema(description = "创建时间")
        private LocalDateTime createTime;
    }

    /**
     * 目标分析信息
     */
    @Data
    public static class GoalAnalysisInfo {
        @Schema(description = "目标ID", example = "1")
        private Long id;

        @Schema(description = "学校名称", example = "清华大学")
        private String universityName;

        @Schema(description = "专业组名称", example = "物理组")
        private String majorGroupName;

        @Schema(description = "专业组代码", example = "001")
        private String universityMajorGroup;

        @Schema(description = "参考年份", example = "2024")
        private Integer year;

        @Schema(description = "最低录取分", example = "680")
        private Integer minScore;

        @Schema(description = "最低位次", example = "100")
        private Integer minRank;

        @Schema(description = "我的等效分", example = "675.5")
        private BigDecimal myEquivalentScore;

        @Schema(description = "我的等效位次", example = "150")
        private Integer myEquivalentRank;

        @Schema(description = "分数差距", example = "-4.5")
        private BigDecimal scoreGap;

        @Schema(description = "位次差距", example = "50")
        private Integer rankGap;

        @Schema(description = "录取概率", example = "冲/稳/保")
        private String probability;
    }
}
